﻿using System;
using System.Collections.ObjectModel;
using System.Windows.Markup;
using System.Windows.Navigation;

using Outcoder;

namespace CalciumTemplateApp
{
	/// <summary>
	/// This class is used by the App class and allows you 
	/// to add custom routing logic via the <c>MapUri</c> method.
	/// </summary>
	[ContentProperty("UriMappings")]
	public sealed class AppUriMapper : UriMapperBase
	{
		public Collection<UriMapping> UriMappings { get; private set; }

		public AppUriMapper()
		{
			UriMappings = new Collection<UriMapping>();
		}

		public override Uri MapUri(Uri uri)
		{
			ArgumentValidator.AssertNotNull(uri, "uri");

			Collection<UriMapping> uriMappings = UriMappings;

			foreach (UriMapping mapping in uriMappings)
			{
				Uri mappedUri = mapping.MapUri(uri);

				if (mappedUri != null)
				{
					return mappedUri;
				}
			}

			/* Perform additional routing logic. */

			//string uriString = uri.ToString();
			//
			//if (uriString.Contains("?Action=ViewfinderLaunch"))
			//{
			//	return new Uri("/Sensors/Camera/PhotoCameraView.xaml",
			//					UriKind.Relative);
			//}

			return uri;
		}
	}
}
